import formJs from "./regexDetail.js"; //新增弹框配置项
import publicForm from "@/components/public/el-form.vue"; //弹框form
import upForm from "@/components/public/up-form.vue"; //文件上传

import TableData from "@/components/public/el-table"; //列表
import imgBox from "../img.vue"; //列表
import echarts from "./echarts.vue"; //列表
import {
    // getPileFoundationDataDetailByFid, //详情
    getPileFoundationDataDetailByTaskNo,//  桩基详情
    savePileCheckFiles

} from "@/api/request.js";
export default {
    props: [
        "dialogVisible", //弹框是否展示
        "dialogTitle", //标题
        "statusNum", //按钮编号 1新增   2编辑取样   3编辑收样  7查看
        "currentRow", //当前行
        "fCompanyid",
        "fCompanyname",
    ],
    data() {
        return {

            // 页签切换
            typeData: [{
                    text: "桩信息",
                    show: true
                },
                {
                    text: "监测信息",
                    show: false
                },
                {
                    text: "曲线",
                    show: false
                },
                {
                    text: "波列图",
                    show: false
                },
                {
                    text: "文件上传",
                    show: false
                },
            ],
            // 页签切换
            visible: "", //弹框展示隐藏
            title: null, //弹框标题
            dialogHeight: null, //弹框高度
            formObj: formJs.formObj,
            table_config: formJs.table_config, //列表
            // 桩信息
            formData: {},
            tableData: [],
            graphfileLists: [], //曲线
            graphDataLists: [],
            polarogramfileLists: [], //雷达
            loading: false, //列表转载
            upObj: formJs.upObj,
            upform: {
                fId:"",
                checkFiles: [], //删除文件id集合
            },
            Filelist: [],
            isLock: false,

        };
    },
    components: {
        publicForm,
        TableData,
        imgBox,
        echarts,
        upForm
    },
    watch: {
        dialogVisible: {
            handler(newVal) {
                if (newVal) {
                    this.visible = newVal;
                }
            },
            immediate: true,
        },
        dialogTitle: {
            handler(newVal) {
                if (newVal) {
                    this.title = newVal;
                }
            },
            immediate: true,
        },
        currentRow: {
            handler(newVal) {
                if (newVal) {
                    this.currentDetail = newVal;
                }
            },
            immediate: true,
        },

        fCompanyid: {
            handler(newVal) {
                if (newVal) {

                    this.fCompanyids = newVal

                }
            },
            immediate: true,
        },
        fCompanyname: {
            handler(newVal) {
                if (newVal) {
                    this.fCompanynames = newVal

                }
            },
            immediate: true,
        },

    },
    created() {
        window.addEventListener("resize", this.getHeight);
        this.getHeight();
    }, //获取页面高度自适应：

    destroyed() {
        window.removeEventListener("resize", this.getHeight);
        this.getHeight();
    },
    mounted() {
        this.userInfo = JSON.parse(sessionStorage.getItem("GxBack-userInfo"));
        // console.log("userInfo", this.userInfo);

        if (this.statusNum == 7) { //查看
            this.btnShow = false //按钮
            this.getDetail({
                // fId: this.currentDetail.fId
                taskNumber:this.currentDetail.fTaskno
            })

        }
        this.getHeight();

    },
    methods: {
        // 刪除文件
        delteFile(file) {
            for (let index = 0; index < this.Filelist.length; index++) {
                if (file.uid == this.Filelist[index].uid) {
                    if (this.Filelist[index].atta == undefined) {
                        this.upform.checkFiles.push({
                            fId: this.Filelist[index].fId,
                        });
                    } else {
                        this.upform.checkFiles.push({
                            fId: this.Filelist[index].atta.fId,
                        });
                    }
                    this.Filelist.splice(index, 1);
                }
            }
        },
        yj_saveForm() {
            // this.userInfo = JSON.parse(sessionStorage.getItem("GxBack-userInfo"));
            // this.formData.userId = this.userInfo.userId; //当前登录人id
            // this.formData.userName = this.userInfo.realName; //当前登录人名称
            if (this.$refs.publicupForm.submitForm()) {
                this.saveForm(this.upform);
            } else {
                console.log("error");
            }
        },
        // 保存
        saveForm(obj) {

            this.loading = true;
            this.isLock = true
            savePileCheckFiles(obj)
                .then((res) => {
                    if (res.errcode == 0) {
                        this.loading = true;
                        this.visible = false;
                        this.$emit("refreshList");
                        this.$message.success("新增成功");
                        this.isLock = false
                    } else {
                        this.loading = true;
                        this.isLock = false
                        this.$message.error(res.msg);
                        console.log("接口报错");
                    }
                })

        },
        // 页签切换
        changeType(e, index) {
            for (let i in this.typeData) {
                if (parseFloat(i) === index) {
                    this.typeData[i].show = true;
                } else {
                    this.typeData[i].show = false;
                }
            }
            // this.typeDataNum = index;
        },
        // 页签切换
        getHeight() {
            var h = document.documentElement.clientHeight; //获取页面可见高度
            this.dialogHeight = h * 0.76 + "px";
        },

        closeDialog() {
            this.$emit("close");
        },

        // 详情
        // 详情
        getDetail(obj) {
            this.loading = true;
            getPileFoundationDataDetailByTaskNo(obj).then((res) => {
                if (res.errcode == 0) {
                    this.loading = false;
                    var data = res.data;
                    this.formData = data.info;

                    this.tableData = res.data.infoList;
                    this.graphfileLists = res.data.graphfileLists; //曲线
                    this.polarogramfileLists = res.data.polarogramfileLists; //雷达
                    this.graphDataLists = res.data.graphDataLists;
                    this.Filelist=res.data.checkFiles;
                    this.upform.fId=data.info.fId;
                    if (this.statusNum == 7) {
                        this.btnShow = false
                        this.formObj.map((item) => {
                            item.disabled = true;
                        });
                    }
                } else {
                    this.loading = false;
                    this.$message.error(res.msg);
                }
            });
        },

    },
};